/**
 * 违章条款奖惩规则 编辑页
 *
 * 作者 admin
 * 日期 2024-08-08 13:20:28
 */
layui.use(['jquery','febs', 'form','laydate', 'validate','util'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        util = layui.util,
        laydate = layui.laydate,
        $view = $('#peccancyClauseRule-edit'),
        $disposeForm = $view.find('#disposeForm'),
        validate = layui.validate;


    form.verify(validate);
    form.render();
    initDate();
    initFormValue();

    function initFormValue() {
        if (peccancyClauseRuleData) {
            form.val("peccancyClauseRule-edit-form", {
                "clauseRuleId": peccancyClauseRuleData.clauseRuleId,
                "tenantId": peccancyClauseRuleData.tenantId,
                "clauseId": peccancyClauseRuleData.clauseId,
                "clauseNo": peccancyClauseRuleData.clauseNo,
                // "clauseType": peccancyClauseRuleData.clauseType,
                "clauseLevel": peccancyClauseRuleData.clauseLevel,
                // "disposeForm": ,
                "referenceMoney": peccancyClauseRuleData.referenceMoney,
                "examineScore": peccancyClauseRuleData.examineScore,
                "clauseContent": peccancyClauseRuleData.clauseContent,
                "executeDate": peccancyClauseRuleData.executeDate,
                "status": peccancyClauseRuleData.status,
            });
            $('#clauseName').text(peccancyClauseRuleData.clauseName)
            febs.initDictItemSelect($disposeForm,'SAFETY_PECCANCY_DISPOSE_FORM',peccancyClauseRuleData.disposeForm,null)
        }else {
            form.val("peccancyClauseRule-edit-form", {
                "tenantId": POPUP_DATA.tenantId,
                "clauseId": POPUP_DATA.clauseId,
            });
            $('#clauseName').text(POPUP_DATA.clauseName)
            febs.initDictItemSelect($disposeForm,'SAFETY_PECCANCY_DISPOSE_FORM',null,null)
        }
    }

    form.on('submit(peccancyClauseRule-edit-form-submit)', function (data) {
        if (data.field.status == "on") {
            data.field.status = '1';
        } else {
            data.field.status = '0';
        }
        addOrUpdate(data.field);
        return false;
    });

    function addOrUpdate(data) {
        febs.modal.confirm('保存', '确定保存奖惩信息？', function () {
            if (data.clauseRuleId && data.clauseRuleId.length > 0) {
                febs.postArray(ctx + 'peccancyClauseRule/update', data, function () {
                    layer.closeAll();
                    febs.alert.success('修改成功');
                    febs.reloadPage();
                });
            } else {
                febs.postArray(ctx + 'peccancyClauseRule', data, function () {
                    layer.closeAll();
                    febs.alert.success('新增成功');
                    $('#febs-peccancyClauseRule').find('#ruleQuery').trigger('click');
                });
            }

        });

    }



    function initDate() {
        //初始化日期控件
        laydate.render({
            elem: '#febs-form-group-date',
            value: new Date(),
            min: util.toDateString(new Date(), "yyyy-MM-dd"),
        })
    }
});